package controllers;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import javax.annotation.PostConstruct;
import javax.faces.application.FacesMessage;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ManagedProperty;
import javax.faces.bean.SessionScoped;
import javax.faces.bean.ViewScoped;
import javax.faces.context.FacesContext;
import javax.faces.event.ActionEvent;
import javax.faces.event.AjaxBehaviorEvent;
import javax.servlet.http.HttpSession;

import org.primefaces.event.RowEditEvent;
import org.primefaces.event.TransferEvent;
import org.primefaces.model.DualListModel;

import services.ComboBebidaXSalonService2;
import services.SalonService;
import services.ComboBebidaService;
import services.BebidaService;
import services.DetalleComboBebidaService;
import modelo.Menu;
import modelo.Salon;
import modelo.Bebida;
import modelo.Detallecombobebida;
import modelo.DetallecombobebidaId;
import modelo.Combobebida;
import modelo.Combobebidaxsalon;
import modelo.CombobebidaxsalonId;
import modelo.Servicioadicionalxsalon;

@ManagedBean(name="combobebidaxsalonBean2")
@ViewScoped
public class ComboBebidaXSalonBean2 implements Serializable {

	/**
	 * 
	 */
	private static final long serialVersionUID = 4237552358568778868L;
	
	@ManagedProperty("#{comboBebidaXSalonService2}")
	private ComboBebidaXSalonService2 combobebidaxsalonService;
	private Combobebidaxsalon combobebidaxsalon = new Combobebidaxsalon();
	private float precio = 0;
	private Combobebidaxsalon combo = new Combobebidaxsalon();
	private List<Combobebidaxsalon> listComboBebidaXSalon = new ArrayList<Combobebidaxsalon>();
	private Combobebidaxsalon combobebidaxsalonSelected = new Combobebidaxsalon();
	
	@ManagedProperty("#{detalleComboBebidaService}")
	private DetalleComboBebidaService detallecombobebidaService;
	private Detallecombobebida detallecombobebida = new Detallecombobebida();
	private Detallecombobebida detallecombobebidaSelected = new Detallecombobebida();
	private List<Detallecombobebida> listDetalleComboBebida = new ArrayList<Detallecombobebida>();
	private int cantidad = 0;
	
	@ManagedProperty("#{salonService}")
    private SalonService serviceSalon;
	private Salon salon = new Salon();
	private List<Salon> listSalones = new ArrayList<Salon>();
	private Salon selectedSalon=new Salon();
	
	@ManagedProperty("#{comboBebidaService}")
    private ComboBebidaService serviceComboBebida;
	private List<Combobebida> listComboBebida = new ArrayList<Combobebida>();
	private Combobebida selectedComboBebida = new Combobebida();
	private Combobebida combobebida = new Combobebida();
	
	@ManagedProperty("#{bebidaService}")
	private BebidaService serviceBebida;
	private List<Bebida> listBebida = new ArrayList<Bebida>();
	private Bebida selectedBebida = new Bebida();
	private Bebida bebida = new Bebida();
	
	public ComboBebidaXSalonBean2() {
		super();
	}

	@PostConstruct
	public void init(){
//		listComboBebida = serviceComboBebida.getListaComboBebida();
//		listSalones = serviceSalon.getListaSalones();
//		listComboBebidaXSalon = combobebidaxsalonService.getListacombobebidaxsalon();
		listBebida = serviceBebida.getListaBebida();

        FacesContext context = javax.faces.context.FacesContext.getCurrentInstance();
        HttpSession sessionActual = (HttpSession) context.getExternalContext().getSession(false);
        Integer salonSel = null;
        
        if (sessionActual!= null)
        {  salonSel = Integer.parseInt(sessionActual.getAttribute("salon").toString());             
        
              salon=serviceSalon.obtenerSalon(salonSel);
        }
        else
        {
        	
        	
        }			
		
	}

	public List<Salon> getListSalones() {
		return listSalones;
	}

	public void setListSalones(List<Salon> listSalones) {
		this.listSalones = listSalones;
	}

	public Salon getSelectedSalon() {
		return selectedSalon;
	}

	public void setSelectedSalon(Salon selectedSalon) {
		this.selectedSalon = selectedSalon;
	}

	public List<Combobebida> getListComboBebida() {
		return listComboBebida;
	}

	public void setListComboBebida(
			List<Combobebida> listComboBebida) {
		this.listComboBebida = listComboBebida;
	}

	public Combobebida getSelectedComboBebida() {
		return selectedComboBebida;
	}

	public void setSelectedComboBebida(
			Combobebida selectedComboBebida) {
		this.selectedComboBebida = selectedComboBebida;
	}

	public float getPrecio() {
		return precio;
	}

	public void setPrecio(float precio) {
		this.precio = precio;
	}
	
	public ComboBebidaXSalonService2 getCombobebidaxsalonService() {
		return combobebidaxsalonService;
	}
	public void setCombobebidaxsalonService(
			ComboBebidaXSalonService2 combobebidaxsalonService) {
		this.combobebidaxsalonService = combobebidaxsalonService;
	}

	public Combobebidaxsalon getCombobebidaxsalon() {
		return combobebidaxsalon;
	}

	public void setCombobebidaxsalon(
			Combobebidaxsalon combobebidaxsalon) {
		this.combobebidaxsalon = combobebidaxsalon;
	}

	public SalonService getServiceSalon() {
		return serviceSalon;
	}

	public void setServiceSalon(SalonService serviceSalon) {
		this.serviceSalon = serviceSalon;
	}

	public ComboBebidaService getServiceComboBebida() {
		return serviceComboBebida;
	}

	public void setServiceComboBebida(
			ComboBebidaService serviceComboBebida) {
		this.serviceComboBebida = serviceComboBebida;
	}

	public Combobebidaxsalon getCombo() {
		return combo;
	}

	public void setCombo(Combobebidaxsalon combo) {
		this.combo = combo;
	}

	public List<Combobebidaxsalon> getListComboBebidaXSalon() {
		return listComboBebidaXSalon;
	}

	public void setListComboBebidaXSalon(
			List<Combobebidaxsalon> listComboBebidaXSalon) {
		this.listComboBebidaXSalon = listComboBebidaXSalon;
	}
	
	public void agregarCombo() {
		detallecombobebida.setBebida(selectedBebida);
		listDetalleComboBebida.add(detallecombobebida);
		detallecombobebida = new Detallecombobebida();
	}	
	
	public void eliminarCombo() {
		//this.listComboBebidaXSalon.remove(combobebidaxsalonSelected);
		this.listDetalleComboBebida.remove(detallecombobebidaSelected);
	}

	public Combobebidaxsalon getCombobebidaxsalonSelected() {
		return combobebidaxsalonSelected;
	}

	public void setCombobebidaxsalonSelected(
			Combobebidaxsalon combobebidaxsalonSelected) {
		this.combobebidaxsalonSelected = combobebidaxsalonSelected;
	}
	
	public String guardarComboBebidaXSalon() throws Exception{
		combobebidaxsalon.setSalon(salon);		
		combobebidaxsalonService.guardarComboBebidaXSalon(listDetalleComboBebida, combobebida, combobebidaxsalon);

		combobebidaxsalon=new Combobebidaxsalon();
		return "ComboRegistrado";
		
	}

	public Combobebida getCombobebida() {
		return combobebida;
	}

	public void setCombobebida(Combobebida combobebida) {
		this.combobebida = combobebida;
	}

	public BebidaService getServiceBebida() {
		return serviceBebida;
	}

	public void setServiceBebida(BebidaService serviceBebida) {
		this.serviceBebida = serviceBebida;
	}

	public List<Bebida> getListBebida() {
		return listBebida;
	}

	public void setListBebida(List<Bebida> listBebida) {
		this.listBebida = listBebida;
	}

	public Bebida getSelectedBebida() {
		return selectedBebida;
	}

	public void setSelectedBebida(Bebida selectedBebida) {
		this.selectedBebida = selectedBebida;
	}

	public Bebida getBebida() {
		return bebida;
	}

	public void setBebida(Bebida bebida) {
		this.bebida = bebida;
	}

	public DetalleComboBebidaService getDetallecombobebidaService() {
		return detallecombobebidaService;
	}

	public void setDetallecombobebidaService(
			DetalleComboBebidaService detallecombobebidaService) {
		this.detallecombobebidaService = detallecombobebidaService;
	}

	public Detallecombobebida getDetallecombobebida() {
		return detallecombobebida;
	}

	public void setDetallecombobebida(Detallecombobebida detallecombobebida) {
		this.detallecombobebida = detallecombobebida;
	}

	public Detallecombobebida getDetallecombobebidaSelected() {
		return detallecombobebidaSelected;
	}

	public void setDetallecombobebidaSelected(
			Detallecombobebida detallecombobebidaSelected) {
		this.detallecombobebidaSelected = detallecombobebidaSelected;
	}

	public List<Detallecombobebida> getListDetalleComboBebida() {
		return listDetalleComboBebida;
	}

	public void setListDetalleComboBebida(
			List<Detallecombobebida> listDetalleComboBebida) {
		this.listDetalleComboBebida = listDetalleComboBebida;
	}

	public int getCantidad() {
		return cantidad;
	}

	public void setCantidad(int cantidad) {
		this.cantidad = cantidad;
	}

	public Salon getSalon() {
		return salon;
	}

	public void setSalon(Salon salon) {
		this.salon = salon;
	}
	
}